package io.lvdaxian.map4.file.stream.config;

import io.lvdaxian.map4.file.stream.common.CommonUtils;
import io.lvdaxian.map4.file.stream.common.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author: lihh
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
  
  private final static Logger LOGGER = LoggerFactory.getLogger(WebConfig.class);
  
  /**
   * 访问外部文件配置
   */
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    String filePath = CommonUtils.getAbsolutePath(Constants.COMMON_VIDEO_PATH).toString();
    LOGGER.info("Add resource locations: {}", filePath);
    registry.addResourceHandler("/**").addResourceLocations("file:" + filePath);
  }
}
